package install.ren.exercise.test.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author jonny
 * Created on 2022/6/7
 */
public class CallbackBlock {
    public static void main(String[] args) throws InterruptedException {
        CompletableFuture<String> x = CompletableFuture.supplyAsync(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
                //throw new RuntimeException("x error");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(">>>>x");
            return "x";
        });
        CompletableFuture<String> y = CompletableFuture.supplyAsync(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
                //throw new RuntimeException("x error");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(">>>>y");
            return "y";
        });

        x.thenAcceptBoth(y, (xx, yy) -> {
            System.out.println("total:" + xx + "+" + yy);
        });



        Thread.currentThread().join();

    }
}
